package com.hand.pp.aspect;/**
 * @author Estelle@앙수청
 * @date 2019/7/18 8:59
 */

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 *  @author Estelle@앙수청
 *  @date 2019/7/18 8:59
 */
@Aspect
@Component
public class ServiceAspect {

    @Pointcut("execution(* com.hand.pp.controller.*.*(..))")
    public void servicePointcut(){}

//    @Before("servicePointcut()")
//    public void beforeFunction(JoinPoint joinPoint){
//        //com.hand.pp.service.impl.UserServiceImpl
//        System.out.println(joinPoint.getSignature().getDeclaringType().getName());
//        //getAllUser
//        System.out.println(joinPoint.getSignature().getName());
//        // [Ljava.lang.Object;@68064457
//        System.out.println(joinPoint.getArgs());
//    }

    @After( "servicePointcut()")
    public void afterFunction(JoinPoint joinPoint){
        System.out.println("afterFunction()");
    }

    @AfterReturning(pointcut = "servicePointcut()", returning = "result")
    public void afterReturnFunction(Object result){
        System.out.println("afterReturnFunction()" + result);
    }

//    @AfterThrowing(pointcut = "servicePointcut()", throwing = "exceptions")
//    public void afterThrowingFunction(Throwable exceptions){
//        System.out.println("afterThrowingFunction()"+exceptions.getMessage());
//    }

    @Around("servicePointcut()")
    public Object aroundFunction(ProceedingJoinPoint proceedingJoinPoint){
        // before
        Object o = null;
        try {
            o = proceedingJoinPoint.proceed();

        } catch (Throwable throwable) {
            // throwing
            throwable.printStackTrace();
        }
        System.out.println("aroundFunction()");
        return o;
    }

}
